import * as fs from "fs";
import * as path from "path";
export namespace StFile {

}

export class StFile {
    constructor(readonly path: string) {

    }
    public list(withFileTypes: boolean = false): Promise<string[]> {
        return new Promise((resolve, reject) => {
            fs.readdir(this.path, { encoding: 'UTF8', withFileTypes }, (err, files: string[]) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(files);
                }
            });
        });
    }
    public getState(): Promise<fs.Stats> {
        return new Promise((resolve, reject) => {
            fs.lstat(this.path, (err, stats) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(stats);
                }
            });
        });
    }
    public exists(): Promise<boolean> {
        return new Promise(resolve => {
            fs.exists(this.path, (exists) => {
                resolve(exists);
            })
        });
    }
    public create(data: string = ''): Promise<void> {
        return new Promise((resolve, reject) => {
            fs.writeFile(this.path, data, { encoding: 'utf8' }, (err) => {
                if (err) {
                    reject(err);
                } else {
                    resolve();
                }
            });
        });
    }
}